package easy.搜索插入位置;

import java.util.ArrayList;

public class Solution {
    public int searchInsert(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        while (left <= right) {
            int middle = (left + right) / 2;
            if (nums[middle] < target) {
                left = middle + 1;
            } else {
                right = middle - 1;
            }
        }
        return left;
    }

    public static void main(String[] args) {
        int[] nums = {1, 3, 5, 5, 5, 6};
        int target = 5;
        int target2 = 2;
        Solution solution = new Solution();
        System.out.println(solution.searchInsert(nums, target));
        System.out.println(solution.searchInsert(nums, target2));
    }
}
